package com.example.sztangli.widgedemo.popwindow;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.example.sztangli.widgedemo.R;
import com.example.sztangli.widgedemo.base.BaseFragment;

import butterknife.BindView;

/**
 * Created by sztangli on 2017/8/10.
 */

public class PopWindowFragment extends BaseFragment {
    @BindView(R.id.bottom)
    LinearLayout bottomLayout;
    @BindView(R.id.button)
    Button button;
    public static final String TAG = "PopWindowFragment";
    public static PopWindowFragment newInstance() {

        Bundle args = new Bundle();

        PopWindowFragment fragment = new PopWindowFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public int getLayoutResId() {
        return R.layout.fragment_popwindow;
    }

    @Override
    public void creatView() {

        View contentView = LayoutInflater.from(getContext()).inflate(R.layout.popwindow_layout, null);
        final PopupWindow popWnd = new PopupWindow(getContext());
        popWnd.setContentView(contentView);
        popWnd.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        popWnd.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(popWnd.isShowing()){
                    popWnd.dismiss();
                }else {
                    popWnd.showAtLocation(bottomLayout, Gravity.TOP,0,0);
                }
            }
        });
    }
}
